import Mock from 'mockjs'

// 用户登录数据
const userData = [{
  username: 'admin',
  password: 'admin'
}, {
  username: '1906A',
  password: '41'
}]

// 拦截登录
Mock.mock('/api/login', 'post', (req) => {
  // 获取发送过来的用户名和密码
  const { username, password } = JSON.parse(req.body)
  // 验证账户密码
  const result = userData.find(item => item.username === username 
      && item.password === password)
  // 返回对应信息
  if(result) {
    return ({
      code: 200,
      data: null,
      mess: '登录成功',
      token: 'XXXXXXXXXXXX'
    })
  } else {
    return ({
      code: 404,
      data: null,
      mess: '账户密码错误！',
    })
  }
})